import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class xxxxx {

    private static class SplitDemo {

        public static String[] split(String rawer, String spliter) {
            //存储分隔后的字符串
            String stringTemp = rawer;
            //存储字符串数组
            ArrayList<String> strings = new ArrayList<>();
            //indexOf(spliter)用来定位分隔符位置
            while (stringTemp.indexOf(spliter) != -1) {
                //截取分隔符前面的字符串存进数组
                String substring = stringTemp.substring(0, stringTemp.indexOf(spliter));
                strings.add(substring);
                //截取分隔符后面的字符串为新字符串
                stringTemp=stringTemp.substring(stringTemp.indexOf(spliter)+spliter .length());
            }

            //如果经过前面的截取，字符串长度不是0就说明字符串内没有分隔符
            if(stringTemp.length()!=0){
                strings.add(stringTemp);
            }
            //数组转为字符串数组
            if(strings.size()>0){
                String[] s = new String[strings.size()];
                int i = 0;
                for (String string : strings) {
                    s[i]=string;
                    i++;
                }
                return s;
            }
            return new String[0];
        }
    }

    @Test
    public void test() {
        System.out.println(Arrays.toString(SplitDemo.split("", "\\")));
        System.out.println(Arrays.toString(SplitDemo.split("aa&&22", "&&")));
        System.out.println(Arrays.toString(SplitDemo.split("aa&&22&&", "&&")));
        System.out.println(Arrays.toString(SplitDemo.split("aa&&||&&", "||")));
    }
}

